<!DOCTYPE html>
<html lang="en">
<head>
    <title>管理系统 - 管理中心</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- <meta ng-include="'head.html'"> -->
    <style type="text/css">

    </style>
    <link rel="stylesheet" href="../lib/css/select.min.css">
    <script src="../lib/js/jquery.min.js" type="text/javascript"></script>
    <script src="../js/build.js?v=1.2" type="text/javascript"></script>
    <script type="text/javascript" src="../lib/js/select.min.js?v=1.1"></script>
    <script src="../js/public.js" type="text/javascript"></script>
</head>
<body class="flat-blue">
<div class="app-container H100" ng-app="myApp" ng-controller="myCtrl">
<div class="row content-container H100">
<div ng-include="'menus.html'" onload="loadReady()"></div>
<div class="container-fluid H100 pb15">
<div class="side-body padding-top H100" id="main" style="padding-top:70px">
    <!------------------Main---------------->
    
    <div style="width:95%; margin:5px 15px 5px 15px; background:#fff" compile="formTpl" 
        class="col-sm-12 col-xs-12">
        
    </div>

    <!-- 模态对话框 -->
    <div ng-include="'modalCompany.html'"></div>
    <!-- End · 模态对话框 -->

    <!------------------End Main---------------------->
</div>  <!--End side-body-->
</div>  <!--End container-fluid-->
</div>  <!--End content-container-->
<div ng-include="'footer.html'"></div>
</div>  <!--End app-container-->

<script type="text/javascript" src="../js/addCompany.js"></script>
<script type="text/javascript" src="../js/editDevice.js?v=1.1"></script>
<script language="javascript">
    var app = angular.module('myApp', ['ui.select']);
    
    app.controller('myCtrl', function($scope) {
        $scope.formTpl = getEditDeviceTpl.txtContent();
        loadCtlBase($scope);

        //// 单条数据
        $scope.item = {"id":-1,"type":"工业", "productionStatus":"未投产"};
        //// 地址信息·支持多字段
        $scope.hideCols = { "LO":"液氧", "LN":"液氮", "LAr":"液氩", "address":"地址" };
        $scope.Categorys = ["常规装置", "高纯装置", "液体装置"];
        $scope.category = "常规装置";        
        $scope.cplist = [{id: -1, name: '请选择公司'}];
        $scope.selected = { value: $scope.cplist[0] };
        //// 选择框改变事件
        $scope.selChange = function(){
            cout($scope.selected);
        };
        initCompany($scope);
        loadForm();


        function loadForm(){
            ajaxData("get_form", {}, function(rst){ 
                $scope.rows = [];
                $scope.selOptions = rst.data.options;
                rst.data.rows.forEach(function(d){
                    if(d.type=="address" || d.field=="companyName")return;
                    if(d.field in $scope.hideCols)d.enable = false;
                    $scope.rows.push(d);
                });
                
                $scope.$apply();
                cout( $scope.rows);
            });

            ajaxData("get_company_names", {}, function(rst){
                if(rst.data.length>0){
                    $scope.cplist = rst.data;
                    $scope.cplist.unshift({id: -1, name: '请选择公司'});
                }
            })
        }
        
        //// 更改大类
        $scope.changeType = function(c){
            $scope.category = c;
            changeType($scope.category, $scope.rows, $scope.item);
            cout($scope.rows);
        };

        $scope.createCompany = function(){
            $scope.getNewCompany();

            $("#myModal1").modal('show');
        };
        // 提交新公司
        $scope.setCompany = function() {
            setCompany($scope, function(id, name){
                $scope.cplist.unshift({id:id, name: name });
                $scope.selected = { value: $scope.cplist[0] };
                $scope.$apply();
            });
        };

        //// address类型字段属系统默认的只记录详细地址_detail，其它的记录全部
        $scope.Submit = function(){
            SubmitRow($scope, $scope.item, function(rst){
                var con=confirm("添加成功，是否继续添加?\r\n点击取消按钮转到数据管理页面"); 
                if(con==true){
                    $scope.item.O = ""; $scope.item.LO = "";
                    $scope.item.N = ""; $scope.item.LN = "";
                    $scope.item.Ar = ""; $scope.item.LAr = "";
                    $scope.item["producer"] = "";
                    $scope.item["operator"] = "";
                    $scope.item["mark"] = "";
                    $scope.item['productionTime'] = '';
                    $scope.$apply();
                }
                else {
                    window.location.href="showDevice.html";
                }
            });
        };

    });

    app.directive('onFinishRenderFilters', FinishRenderFilters);  
    app.directive('compile', function ($compile) {
        return function (scope, element, attrs) {
            scope.$watch(
              function (scope) {return scope.$eval(attrs.compile); },
              function (value) {
                  element.html(value);
                  $compile(element.contents())(scope);
              }
            );
        };
    });
    


    $(document).ready(function(){
        $('.date').datetimepicker({
            format: 'yyyy-mm-dd', language:'zh-CN', autoclose:true, minView:"month"
        });
    });    

</script>

</body>
</html>
